public class TwoArrayExercise5 {
    public static void main(String[] args) {
        int[][] arr = new int[10][10];

        int start = 1;
        int end = arr.length * arr[0].length;
        int leftColumn = 0;
        int rightColumn = arr[0].length-1;
        int upLine = 0;
        int downLine = arr.length-1;
        while (start<=end ) {
            //从左往右（上面）
            for(int j=leftColumn; j<=rightColumn && start<=end; j++){
                arr[upLine][j] = start++;
            }

            //从上往下
            for(int j=upLine+1; j<=downLine && start<=end; j++){
                arr[j][rightColumn] = start++;
            }

            //从右往左（下面）
            for(int j=rightColumn-1; j>=leftColumn && start<=end; j--){
                arr[downLine][j] = start++;
            }

            //从下往上
            for(int j=downLine-1; j>upLine && start<=end;j--){
                arr[j][leftColumn]=start++;
            }

            leftColumn++;
            rightColumn--;
            upLine++;
            downLine--;
        }

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j]+"\t");
            }
            System.out.println();
        }
    }
}
